package com.ocom.webapi.controller;

import com.ocom.common.constant.WebApiServiceUrl;
import com.ocom.common.entity.payconfig.EntityRechargeRule;
import com.ocom.common.resp.Result;
import com.ocom.webapi.feign.PayConfigClientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: TODO
 * @Author: 朱晖
 * @Date: 2022/11/10
 **/
@Slf4j
@RestController
@PreAuthorize("@pms.hasRole('ROLE_WEB')" )
public class XfRechargeRuleController {


	@Autowired
	private PayConfigClientService payConfigClientService;

	@PostMapping(WebApiServiceUrl.Url_getRechargeRule)
	public Result getRechargeRule(Long comId, @RequestParam(value = "subAccount",defaultValue ="0",required = false) Integer subAccount){
		return payConfigClientService.getRechargeRule(comId,subAccount);
	}

	@PostMapping(WebApiServiceUrl.Url_setRechargeRule)
	public Result setRechargeRule(@RequestBody EntityRechargeRule entityRechargeRule){
		if(null==entityRechargeRule.getSubAccount()){
			entityRechargeRule.setSubAccount(0);
		}
		return payConfigClientService.setRechargeRule(entityRechargeRule);
	}

	@PostMapping(WebApiServiceUrl.Url_deleteRechargeRule)
	public Result deleteRechargeRule(@RequestBody EntityRechargeRule entityRechargeRule){
		if(null==entityRechargeRule.getSubAccount()){
			entityRechargeRule.setSubAccount(0);
		}
		return payConfigClientService.deleteRechargeRule(entityRechargeRule);
	}

}
